package com.ruoyi.web.controller.basicInfo;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.basicInfo.domain.Plant;
import com.ruoyi.basicInfo.service.IPlantService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 电厂信息Controller
 * 
 * @author zbw
 * @date 2022-07-13
 */
@RestController
@RequestMapping("/basicInfo/plant")
public class PlantController extends BaseController
{
    @Autowired
    private IPlantService plantService;

    /**
     * 查询电厂信息列表
     */
    @PreAuthorize("@ss.hasPermi('basicInfo:plant:list')")
    @GetMapping("/list")
    public TableDataInfo list(Plant plant)
    {
        startPage();
        List<Plant> list = plantService.selectPlantList(plant);
        return getDataTable(list);
    }

    /**
     * 导出电厂信息列表
     */
    @PreAuthorize("@ss.hasPermi('basicInfo:plant:export')")
    @Log(title = "电厂信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Plant plant)
    {
        List<Plant> list = plantService.selectPlantList(plant);
        ExcelUtil<Plant> util = new ExcelUtil<Plant>(Plant.class);
        util.exportExcel(response, list, "电厂信息数据");
    }

    /**
     * 获取电厂信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('basicInfo:plant:query')")
    @GetMapping(value = "/{powerPlantId}")
    public AjaxResult getInfo(@PathVariable("powerPlantId") String powerPlantId)
    {
        return AjaxResult.success(plantService.selectPlantByPowerPlantId(powerPlantId));
    }

    /**
     * 新增电厂信息
     */
    @PreAuthorize("@ss.hasPermi('basicInfo:plant:add')")
    @Log(title = "电厂信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Plant plant)
    {
        return toAjax(plantService.insertPlant(plant));
    }

    /**
     * 修改电厂信息
     */
    @PreAuthorize("@ss.hasPermi('basicInfo:plant:edit')")
    @Log(title = "电厂信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Plant plant)
    {
        return toAjax(plantService.updatePlant(plant));
    }

    /**
     * 删除电厂信息
     */
    @PreAuthorize("@ss.hasPermi('basicInfo:plant:remove')")
    @Log(title = "电厂信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{powerPlantIds}")
    public AjaxResult remove(@PathVariable String[] powerPlantIds)
    {
        return toAjax(plantService.deletePlantByPowerPlantIds(powerPlantIds));
    }
}
